在已經簽到的人員增加一個打勾的圖示
我是沒想到這種簡單的功能AI也會出錯,他沒有增加在簽到完成當下的頁面刷新,導致要切換到其他頁面再回來才會刷新
private func performCheckIn(for user: User, note: String?) {
tbvselect.reloadData()
}
// 返回每一行的內容
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UserCell", for: indexPath)
// 獲取對應的使用者資料
if let currentUser = users?[indexPath.row] {
cell.textLabel?.text = "\(currentUser.Name) (\(currentUser.userId))"
// 檢查用戶是否在今天已經簽到
if let lastCheckInTime = currentUser.lastCheckInTime {
let calendar = Calendar.current
let today = calendar.startOfDay(for: Date())
let checkInDate = calendar.startOfDay(for: lastCheckInTime)
// 如果是今天簽到的,顯示打勾圖示
if calendar.isDate(today, inSameDayAs: checkInDate) {
// 使用系統自帶的打勾圖標
cell.accessoryType = .checkmark
cell.tintColor = .systemGreen // 使用綠色
} else {
cell.accessoryType = .none
}
} else {
cell.accessoryType = .none
}
} else {
cell.textLabel?.text = "未知使用者"
cell.accessoryType = .none
}
return cell
}